package com.cts.learninglibrary.controller;

import com.cts.learninglibrary.pojo.Label;
import com.cts.learninglibrary.service.LabelService;
import com.cts.learninglibrary.util.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: kwanghuee
 * @date: 2020/8/24 13:36
 */
@RestController
public class LabelController {

    @Resource
    private LabelService labelService;

    @ApiOperation(value = "查询全部标签")
    @GetMapping("/getLabels")
    public R getLabelList(Integer userId) {
        List<Label> labels = labelService.findByUserId(userId);
        return R.ok(labels, "成功");
    }

    @ApiOperation(value = "新增标签")
    @PostMapping("/addLabel")
    public R addLabel(Integer userId, String labelName) {
        return R.ok(labelService.addLabel(userId, labelName), "新增成功");
    }

    @ApiOperation(value = "根据id删除标签")
    @PostMapping("/deleteLabel")
    public R deleteLabel(Integer id) {
        return R.ok(labelService.deleteLabel(id), "删除成功");
    }

    @ApiOperation(value = "修改标签")
    @PostMapping("/updateLabel")
    public R updateLabel(Integer id,Integer userId,String labelName){
        return R.ok(labelService.updateLabel(id, userId, labelName));
    }
}
